import type { VxeGridProps } from '#/adapter/vxe-table';
import type { FormSchemaGetter } from '#/adapter/form';
import dayjs from 'dayjs';
import { z } from '#/adapter/form';

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  { title: '存货名称', field: 'inventoryName' },
  { title: '当前数量', field: 'currentQuantity' },
  { title: '批次号', field: 'batchNumber' },
  { title: '位置', field: 'locationName' },
  {
    title: '最后修改时间',
    field: 'lastModificationTime',
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
    },
  },
  {
    title: '创建时间',
    field: 'creationTime',
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    resizable: false,
    width: '200',
  },
];

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'inventoryName',
    label: '存货名称',
  },
  {
    component: 'InputNumber',
    fieldName: 'minQuantity',
    label: '最小数量',
  },
  {
    component: 'InputNumber',
    fieldName: 'maxQuantity',
    label: '最大数量',
  },
  {
    component: 'Input',
    fieldName: 'batchNumber',
    label: '批次号',
  },
  {
    component: 'Input',
    fieldName: 'locationName',
    label: '位置名称',
  },

  {
    component: 'RangePicker',
    fieldName: 'creationTime',
    label: '创建时间',
  },
];

export const modalSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
    label: '主键',
  },
  {
    component: 'Input',
    fieldName: 'inventoryName',
    label: '存货名称',
    rules: z.string().min(1, { message: '请输入存货名称' }),
  },
  {
    component: 'InputNumber',
    fieldName: 'currentQuantity',
    label: '当前数量',
    rules: z.number().min(0, { message: '数量不能小于0' }),
    componentProps: {
      min: 0,
      precision: 0,
      max: 2147483647,
      style: { width: '100%' }
    },
  },
  {
    component: 'Input',
    fieldName: 'batchNumber',
    label: '批次号',
    rules: z.string().min(1, { message: '请输入批次号' }),
  },
  {
    component: 'Input',
    fieldName: 'locationName',
    label: '位置',
    rules: z.string().min(1, { message: '请输入位置' }),
  },
];
